package 合并两个有序链表;

public class Solution {
    //方法一递归

    //迭代
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode prehead = new ListNode(-1);
        ListNode pre = prehead;
        while(l1!=null && l2!=null){
            if(l1.val <= l2.val){
                pre.next = l1;
                pre = pre.next;
                l1 = l1.next;
            }else{
                pre.next = l2;
                pre = pre.next;
                l2 = l2.next;
            }
        }
        pre.next = l1!=null ? l1 :l2;
        return prehead.next;
    }

    
}
